package com.itkaien.AopAnno.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyadviceAnno {


    @Pointcut("execution(* com.itkaien.AopAnno.impl.UserServiceImplAnno.*(..))")
    public void pointcut(){
        System.out.println("pointcut");
    }



    //前置通知 ： 在目标方法执行之前执行
    @Before("execution(* com.itkaien.AopAnno.impl.UserServiceImplAnno.*(..))")
    public void before(){
        System.out.println("beforeAnno");
    }

    @AfterReturning("execution(* com.itkaien.AopAnno.impl.UserServiceImplAnno.*(..))")
    //后置通知 ： 当目标方法正常返回时执行
    public void afterReturning(ProceedingJoinPoint proceedingJoinPoint){
        System.out.println("around afterReturning Anno");
    }



    public void afterReturning(){
        System.out.println("afterReturning");
    }

    //异常通知 ： 当目标方法出现异常时执行
    @AfterThrowing(pointcut = "execution(* com.itkaien.AopAnno.impl.UserServiceImplAnno.*(..))",throwing = "e", argNames = "e")
    public void afterThrowing(Throwable e){
        System.out.println("afterThrowing");
    }

    @Around("execution(* com.itkaien.AopAnno.impl.UserServiceImplAnno.*(..))")
    //环绕通知 ： 在目标方法执行前后执行
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("around before");
        proceedingJoinPoint.proceed();
        System.out.println("around after");
    }


    //最终通知 ：不管运行是否出现异常，都会执行
    @After("MyadviceAnno.pointcut()")
    public void after(){
        System.out.println("afterAnno");
    }



}
